import threading
import time

# 定义一个线程函数
def thread_function(name, num):
    for i in range(5):
        print(f"Thread {name}: {i}")
        time.sleep(num)

if __name__ == "__main__":
    # 定义线程数量
    num_threads = 5

    # 创建一个线程列表
    threads = []

    # 创建线程对象
    for num in range(num_threads):
        # thread = threading.Thread(target=thread_function, args=(num, num))
        thread = threading.Thread(target=thread_function, kwargs={"name": num, "num": num})
        # 启动线程
        thread.start()
        threads.append(thread)

    # 在主线程中执行其他任务
    for i in range(5):
        print(f"Main Thread: {i}")
        time.sleep(1)

    # 等待所有线程完成
    for thread in threads:
        thread.join()

    print("线程完成")
